package system;

import java.io.File;
import java.io.IOException;

public class Background {
	
	Actor[] bglist;
	int speed;
	
	public Background(int speed){
		try{
		AnimatedSprite background = new AnimatedSprite(new File("assets/sprites/background.png"), 480, 270, false, 0);
		AnimatedSprite bg1 = new AnimatedSprite(new File("assets/sprites/pbg1.png"), 480, 270, false, 0);
		AnimatedSprite bg2 = new AnimatedSprite(new File("assets/sprites/pbg2.png"), 480, 270, false, 0);
		Actor bgst = new Actor("Stationary Background", background, 0, 0, 0, 0, 0);
		Actor bg1a = new Actor("Parallax", bg1, 0, 0, -speed, 0, 0);
		Actor bg1b = new Actor("Parallax", bg1, 480, 0, -speed, 0, 0);
		Actor bg2a = new Actor("Parallax", bg2, 0, 0, -speed/2, 0, 0);
		Actor bg2b = new Actor("Parallax", bg2, 480, 0, -speed/2, 0, 0);
		this.bglist = new Actor[5];
		bglist[0] = bgst;
		bglist[1] = bg2b;
		bglist[2] = bg2a;
		bglist[3] = bg1b;
		bglist[4] = bg1a;
		
		}
		catch(IOException e){
			System.out.println("Couldn't load background images.");
			System.exit(0);
		}
		
		this.speed = speed;
	}
	
	public void update(){
		for(int i=0; i<bglist.length; i++){
			bglist[i].update();
		}
	}
	
	public int getLength(){
		return bglist.length;
	}
	
	public Actor getActor(int index){
		return bglist[index];
	}

}
